// pages/appointHistoryC/appointHistoryC.js
var util = require('../../utils/util');
let today = util.formatTime(new Date())
Page({
  data: {
    activeNum: 1,
    appoint: [],
    appointt: [],
    today: today,
  },
  onLoad() {
    //拿所有预约信息
    // this.takeAllAppoint()
    this.takeNowAppoint()
  },
  //获取所有预约信息
  takeAllAppoint() {
    var that = this
    //拿账号
    //根据账号取得这个人的所有预约信息
    wx.cloud.callFunction({
      name: 'appoint',
      data: {
        action: 'findAll',
      }
    }).then(res => {
      console.log('获取所有预约信息成功', res)
      that.setData({
        appoint: res.result.data.reverse(),
      })
    }).catch(res => {
      console.log('获取所有预约信息失败', res)
    })
  },
  //获取正在预约信息
  takeNowAppoint() {
    var that = this
    wx.cloud.callFunction({
      name: 'appoint',
      data: {
        action: 'findAShow',
        appointDay: today,
        isPassed: false,
        isOver: false,
      }
    }).then(res => {
      console.log('获取当天正在预约信息成功', res)
      that.setData({
        appointt: res.result.data,
      })
    }).catch(res => {
      console.log('获取当天正在预约信息失败', res)
    })
  },
  bindtap1() {
    this.setData({
      activeNum: 1
    })
    this.takeNowAppoint()
  },
  bindtap2() {
    this.setData({
      activeNum: 2
    })
    this.takeAllAppoint()
  },
  bindtap3() {
    this.setData({
      activeNum: 3
    })
    this.takeAllAppoint()
  },
  //点击正在进行的预约进入明细
  gotoAppointDetail(e) {
    console.log(e.currentTarget.dataset.flowid)
    wx.navigateTo({
      url: '/pages/seeMyAppoint/seeMyAppoint?flowId=' + e.currentTarget.dataset.flowid,
    })
  },
  //查看已完成的订单
  seeOrder(e) {
    wx.navigateTo({
      url: '/pages/order/order?flowId=' + e.currentTarget.dataset.flowid,
    })
  }
})